﻿/*
 * Ext JS Library 2.1
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

Ext.onReady(function(){
    var frmLogin = new Ext.form.FormPanel({
        baseCls: 'x-plain',
		//ctCls:'a',
		//cls:'b',
        layout:'absolute',
        url:'loginCheck.php',
        defaultType: 'textfield',
	

        items: [{
            x: 5,
            y: 10,
            xtype:'label',
            text: '用户名：'
        },{
            x: 65,
            y: 5,
            name: 'login',
            value:'',
            anchor:'100%'  // anchor width by percentage
        },{
            x: 5,
            y: 40,
            xtype:'label',
            text: '密　码：'
        },{
            x: 65,
            y: 35,
            name: 'password',
            inputType: 'password',
            value:'',
            anchor: '100%'  // anchor width by percentage
        }]
    });

    var win = new Ext.Window({
        title: '登　陆',
        width: 300,
        height:140,
        minWidth: 300,
        minHeight: 140,
        maxWidth: 300,
        maxHeight: 140,
        layout: 'fit',
	//	cls:'a',
        plain:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: frmLogin,
		closable: false,

        buttons: [{
            text: '登陆',
            handler:function(){
            	var u = frmLogin.form.findField('login').getValue();
            	var p = frmLogin.form.findField('password').getValue();
            	if (!u || !p){
            		Ext.MessageBox.alert('登陆失败', "请输入用户名和密码"); 
            	}
            	else{
	            	frmLogin.form.submit({
					     waitTitle:"请稍候",
					     waitMsg:"正在验证登陆信息，请稍候。。。。。。",
					     url:"get.php",
					     method:"POST",
						params:{
			    			action:'user'
			    			,operation: 'login'
						},
					     success:function(from,action){
							var seesion = action.result.info;
							Cookies.set("session", seesion); 
					      	self.location = 'main.php';
					     },
					     failure:function(form,action){
					     	Ext.MessageBox.alert('登陆失败', action.result.info); 
					     }
					})
			     }
			 }
        },{
            text: '取消',
            handler:function(){
            	window.close();
            }
        }]
    });

    win.show();
    
    function check(){
    	alert("alert");
    }
    
    function closeWindow()
    {
    	window.close();
    }
});